package com.enjoy.xbase.nest;

import android.view.ViewGroup;
import android.view.ViewTreeObserver;


public class NestDemo implements NestListener {




    private void initNest(ParentScrollView parentScrollView,ChildView childView){
        childView.setParentView(parentScrollView);
        parentScrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                ViewGroup.LayoutParams layoutParams=childView.getLayoutParams();
                layoutParams.height=parentScrollView.getHeight();
                childView.setLayoutParams(layoutParams);
            }
        });
        parentScrollView.setNestListener(this);
        childView.setNestListener(this);
    }
    @Override
    public boolean allowParent(int deltaX, int deltaY) {
        if (deltaY<0){//下滑
//            if(parentScrollView.isToBottom()){//
//                return false;
//            }else{
//                return true;
//            }
        }else if (deltaY>0){//上滑
//            if(parentScrollView.isToTop()){//
//                return false;
//            }else if (censusFragment.isToTop()){
//                return true;
//            }else{
//                return false;
//            }
        }else{
            return false;
        }
        return true;
    }

}
